package org.wdcode.back.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;

import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.ui.AbstractUITag;
import org.wdcode.common.util.CommonUtil;

import com.opensymphony.xwork2.util.ValueStack;

/**
 * 封装Struts2 UI标签
 * @author WD
 * @since JDK6
 * @version 1.0 2010-03-25
 */
public abstract class BaseUITag extends AbstractUITag {
	// 序列化ID
	private static final long	serialVersionUID	= 1868471118076460249L;
	// 声明一个AbstractUITag
	protected AbstractUITag		tag;

	@Override
	public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
		return CommonUtil.isEmpty(tag) ? new Component(stack) : tag.getBean(stack, req, res);
	}

	/**
	 * 标签结束
	 */
	@Override
	public int doEndTag() throws JspException {
		return CommonUtil.isEmpty(tag) ? EVAL_PAGE : tag.doEndTag();
	}

	/**
	 * 标签开始
	 */
	@Override
	public int doStartTag() throws JspException {
		// 初始化
		init();
		// 标签不为空设置属性
		if (!CommonUtil.isEmpty(tag)) {
			tag.setPageContext(pageContext);
		}
		// 标签开始
		return CommonUtil.isEmpty(tag) ? SKIP_BODY : tag.doStartTag();
	}

	/**
	 * 初始化操作
	 */
	protected abstract void init();
}
